<template>
	<view class="container">
		<span>员工：<span style="color: red;">{{ parentRow.workName }}</span></span>
		<uv-calendars ref="calendars" @confirm="confirm" />
		<view class="flex">
			<span>日期：</span>
			<uv-input style="margin-top: 10rpx;" @click="open" v-model="dateValue" placeholder="请选择日期" disabled
				disabledColor="#ffffff"></uv-input>
		</view>

		<view class="btns">
			<button @click="search" class="button">搜索</button>
			<button @click="reset" class="buttonRS">重置</button>
		</view>

		<uv-notify ref="notify" type="error"></uv-notify>

		<uni-table border stripe emptyText="暂无更多数据">
			<!-- 表头行 -->
			<uni-tr>
				<uni-th :width="60" align="center">日期</uni-th>
				<uni-th :width="70" align="center">工资</uni-th>
			</uni-tr>
			<!-- 表格数据行 -->
			<uni-tr v-for="item in tableList">
				<uni-td align="center" @click="dateClick(item)" style="color: #3C9CFF;">{{item.monthAndYearAndDay}}</uni-td>
				<uni-td align="center">{{item.amt}}</uni-td>
			</uni-tr>
			<uni-tr>
				<uni-td align="center">合计</uni-td>
				<uni-td align="center">{{total}}</uni-td>
			</uni-tr>
		</uni-table>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				total: 0,
				tableList: [],
				dateValue: '',
				parentRow: {}
			}
		},
		methods: {
			reset() {
				this.dateValue = ''
			},
			search() {
				this.getTableList()
			},
			dateClick(row) {
				console.log(2222222222222, row, this.parentRow)
				const obj = {
					...this.parentRow,
					...row,
				}
				uni.navigateTo({
					url: '/pages/outputSearch/progressSearch/progressSearch?parentRow=' + JSON.stringify(obj)
				})
			},
			confirm(e) {
				// console.log(e)
				this.dateValue = e.fulldate
			},
			open() {
				this.$refs.calendars.open();
			},
			formatDate(timestamp) {
				let date = new Date(timestamp);
				let year = date.getFullYear();
				let month = "0" + (date.getMonth() + 1); // getMonth()返回的月份是从0开始的，这里添加前导零
				return year + "-" + month.substr(-2); // substr(-2)确保至少取两位数字，避免月份或日期是个位数时的问题
			},
			getTableList() {
				let token = uni.getStorageSync('token');
				let userInfo = uni.getStorageSync('userInfo')
				console.log(userInfo)
				uni.request({
					url: '/kl/pad/stitchProducedValue/getEmployeeDailySalary',
					header: {
						'Authorization': token //自定义请求头信息
					},
					data: {
						...userInfo.departmentList[0],
						...this.parentRow,
						monthAndYear: this.dateValue,
					},
					method: "POST",
					success: (res) => {
						console.log({
							...userInfo.departmentList[0],
							...this.parentRow,
							monthAndYear: this.dateValue
						}, res)
						if (res.data.code === 200) {
							this.tableList = res.data.data.list
							this.total = res.data.data.totalAmt
						} else {
							this.$refs.notify.show({
								message: res.data.message
							});
						}
					}
				});
			},
		},
		onLoad(data) {
			console.log(33333333333333,JSON.parse(data.parentRow))
			this.parentRow = JSON.parse(data.parentRow)
			this.dateValue = JSON.parse(data.parentRow).monthAndYear
			this.getTableList()
		}
	}
</script>

<style>
	.container {
		padding: 0 30rpx 0;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.btns {
		margin-bottom: 30rpx;
		margin-top: 30rpx;
		display: flex;
		justify-content: space-between;
	}
</style>